﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NetCMS.Web.manage.collect
{
    public partial class loglist : System.Web.UI.Page
    {
        protected string getQueryString(string key)
        {
            if (Request.QueryString[key] == null || Request.QueryString[key].Trim() == "")
                return "";
            else
                return HttpUtility.HtmlEncode(Request.QueryString[key].Trim());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string action = this.getQueryString("action");
                if (!string.IsNullOrEmpty(action))
                {
                    switch (action)
                    {
                        //case "del": del(); break;
                        default: break;
                    }
                }
                else
                {
                    Query(" 1=1", "");
                }
            }
        }

        private void Query(string str, string url)
        {
            dsSection = new BLL.Section().GetList(" bookid=" + bid);
            this.ddl_section.DataSource = dsSection.Tables[0].DefaultView;
            //this.ddl_parentid.DataValueField = "cid";
            //this.ddl_parentid.DataTextField = "cname";
            this.ddl_section.DataBind();
            ListItem itemAll = new ListItem();
            itemAll.Text = "无分卷";
            itemAll.Value = "0";
            ddl_section.Items.Insert(0, itemAll);


            book = new BLL.Book().GetModel(int.Parse(bid));
            str += " and c.bookid=" + bid;
            string sid = Request.QueryString["sid"];

            //listpage分页                        
            ListPager1.Urlstring = "chapterlist.aspx?page=$p$&bid=" + bid;
            if (!string.IsNullOrEmpty(sid)) //有分卷
            {
                str += " and c.sectionid=" + sid;
                ListPager1.Urlstring += "&sid=" + sid;
            }
            string stitle = Request.QueryString["stitle"];
            if (!string.IsNullOrEmpty(stitle)) //搜索
            {
                str += " and pname like '%" + stitle + "%'";
                ListPager1.Urlstring += "&sid=" + sid + "&stitle=" + stitle;
            }
            ListPager1.Urlstring += url;
           

            pageindex = Request.QueryString["page"] == null ? 1 : Convert.ToInt32(Request.QueryString["page"]);
            int pagecount = 0, pagesize = Utility.Class1.PageSize;
            dsChapter = new BLL.Chapter().GetList(" chapter c left join section s on c.sectionid=s.sid", " pid ",
                "pid,pname,c.bookid as bname,c.addtime,c.edittime,c.descript,orderby,s.sid,s.sname,(select top 1 case when charindex('<img',content)>0 then 1 else 0 end from tcontent where pid=c.pid) as img",
                pageindex, pagesize, str, " orderby desc,pid desc", out  allcount, out pagecount);



            ListPager1.Pagecount = pagecount;
            ListPager1.Pageindex = pageindex;
            ListPager1.PagerAlign = MyPage.ListPager.pageralign.right;
            ListPager1.PageStyle = MyPage.ListPager.pagestyle.style4;

        }

        
    }
}
